package function

import (
	"fmt"
	"math/rand"
	"time"
)

var phoneSuffix = [...]string{"130", "131", "132", "133", "135", "137", "138", "170", "187", "189"}

type PhoneFunction struct {
	size int // 生成数量
	data []interface{}
}

var headerNumsLen = len(phoneSuffix)

func randomPhone() string {
	header := phoneSuffix[rand.Intn(headerNumsLen)]
	body := fmt.Sprintf("%08d", rand.Intn(99999999))
	phone := header + body
	return phone
}

func DefaultPhone(size int) *PhoneFunction {
	return &PhoneFunction{
		size: size,
		data: make([]interface{}, size),
	}
}

func (f *PhoneFunction) Build() []interface{} {
	rand.Seed(time.Now().UTC().UnixNano())
	for i := 0; i < f.size; i++ {
		f.data[i] = randomPhone()
	}
	return f.data
}
